<div class="layui-fluid">
    <div class="layui-breadcrumb jy-breadcrumb">

    </div>
    <div class="layui-tab" lay-filter="showInfo" style="background-color:#FFFFFF">
        <ul class="layui-tab-title">
            <li class="layui-this" lay-id="1">编辑</li>
            <li lay-id="2">图片</li>
        </ul>
        <input type="hidden" id='tabtype' value='1'>
        <div class="layui-tab-content" style="background-color:#FFFFFF">
            <div class="layui-tab-item layui-show">
                <div class="layui-card">
                    <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="LAY-list-form">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">编辑人员</label>
                                <div class="layui-input-block">
                                    <select name="operator" xm-select="user" xm-select-search="/index/User/getUserByName" xm-select-radio=""></select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">SKU</label>
                                <div class="layui-input-block">
                                    <input type="text" name="sku" placeholder="多个用空格或逗号隔开" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">SPU</label>
                                <div class="layui-input-block">
                                    <input type="text" name="spu" placeholder="" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">制作状态</label>
                                <div class="layui-input-inline">
                                    <select name="status" type="select" xm-select="select1">
                                        <option value="">请选择</option>
                                        <option value="2">待制作</option>
                                        <option value="3">待审核</option>
                                        <option value="5">已制作</option>
                                        <option value="4">已驳回</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline ">
                                <label class="layui-form-label">分派日期</label>
                                <div class="layui-input-block layui-jy-date">
                                    <input type="text" class="layui-input" id="date1" name="assign_time" placeholder="">
                                </div>
                            </div>
                            <div class="layui-inline ">
                                <label class="layui-form-label">完成日期</label>
                                <div class="layui-input-block layui-jy-date">
                                    <input type="text" class="layui-input" id="date2" name="finish_time" placeholder="">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">制作类别</label>
                                <div class="layui-input-block">
                                    <select name="category" >
                                        <option value="">请选择</option>
                                        <option value="1">新品</option>
                                        <option value="2">老品</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">交接类型</label>
                                <div class="layui-input-block">
                                    <input type="text" name="handover_type" placeholder="" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">交接备注</label>
                                <div class="layui-input-block">
                                    <input type="text" name="handover_remarks" placeholder="" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">SKU名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="skuName" placeholder="" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label"></label>
                                <button class="layui-btn search1" lay-submit lay-filter="LAY-list-search">查询</button>
                                <button type="button" class="layui-btn layui-btn-primary tabreset">重置</button>
                                <input type="hidden" id='tabtype' value='1'>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-card-body">
                    <div class="layui-form" lay-filter="batchOp-form2">
                        <div class="layui-form-item" style="padding: 0; margin: 0; margin-top: -14px;">
                            <div class="layui-inline">
                                <select lay-filter="batchOp2" >
                                    <option value="0" selected>批量操作</option>
                                    <option value="1">导出数据</option>
                                    <option value="2">批量制作</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <table id="LAY-list-normal1"  lay-filter="LAY-list-normal1"></table>
                    <!-- 行内工具 -->
                    <script type="text/html" id="operation1">
                        <a class="layui-btn layui-btn-xs" href="/#/Datamanufacture/skuDetails/id={{d.id}}" >详情</a>
                        <br/><br/>
                        {{# if(d.manufacture_status==2 || d.manufacture_status==4){ }}
                        <a class="layui-btn layui-btn-xs" href="/#/Datamanufacture/manufactureEdit/id={{d.id}}" >编辑</a>
                        {{# } }}
                    </script>
                </div>
            </div>
            <div class="layui-tab-item">     
                <div class="layui-card">
                    <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="LAY-list-form1">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">图片人员</label>
                                <div class="layui-input-block">
                                    <select name="operator" xm-select="user1" xm-select-search="/index/User/getUserByName" xm-select-radio=""></select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">SKU</label>
                                <div class="layui-input-block">
                                    <input type="text" name="sku" placeholder="多个用空格或逗号隔开" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">SPU</label>
                                <div class="layui-input-block">
                                    <input type="text" name="spu" placeholder="" autocomplete="off" class="layui-input">
                                </div>
                            </div>
<!--                             <div class="layui-inline">
                                <label class="layui-form-label">交接类型：</label>
                                <div class="layui-input-block">
                                    <input type="text" name="type" placeholder="" autocomplete="off" class="layui-input">
                                </div>
                            </div> -->
                            <!--<div class="layui-inline">-->
                                <!--<label class="layui-form-label">制作状态</label>-->
                                <!--<div class="layui-input-block">-->
                                    <!--<select name="status" >-->
                                        <!--<option value="">请选择</option>-->
                                        <!--<option value="2">待制作</option>-->
                                        <!--<option value="5">已制作</option>-->
                                        <!--<option value="4">已驳回</option>-->
                                    <!--</select>-->
                                <!--</div>-->
                            <!--</div>-->

                            <div class="layui-inline">
                                <label class="layui-form-label">制作状态</label>
                                <div class="layui-input-inline">
                                    <select name="status" type="select" xm-select="select2">
                                        <option value="">请选择</option>
                                        <option value="2">待制作</option>
                                        <option value="5">已制作</option>
                                        <option value="4">已驳回</option>
                                    </select>
                                </div>
                            </div>

                            <div class="layui-inline ">
                                <label class="layui-form-label">分派日期</label>
                                <div class="layui-input-block layui-jy-date">
                                    <input type="text" class="layui-input" id="date3" name="assign_time" placeholder="">
                                </div>
                            </div>
                            <div class="layui-inline ">
                                <label class="layui-form-label">完成日期</label>
                                <div class="layui-input-block layui-jy-date">
                                    <input type="text" class="layui-input" id="date4" name="finish_time" placeholder="">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">制作类别</label>
                                <div class="layui-input-block">
                                    <select name="category" >
                                        <option value="">请选择</option>
                                        <option value="1">新品</option>
                                        <option value="2">老品</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">交接类型</label>
                                <div class="layui-input-block">
                                  <input type="text" name="handovertype" autocomplete="off" placeholder="" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">交接备注</label>
                                <div class="layui-input-block">
                                    <input type="text" name="handover_remarks" placeholder="" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label"></label>
                                <button class="layui-btn search2" lay-submit lay-filter="LAY-list-search">查询</button>
                                <button type="button" class="layui-btn layui-btn-primary tabreset">重置</button>
                            </div>
                        </div>
                    </div>
                </div>       
                <div class="layui-card-body">
                    <div class="layui-form" lay-filter="batchOp-form">
                        <div class="layui-form-item" style="padding: 0; margin: 0; margin-top: -14px;">
                            <div class="layui-inline">
                                <select lay-filter="batchOp" >
                                    <option value="0" selected>批量操作</option>
                                    <option value="1">导出数据</option>
                                    <option value="2">批量提交</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <table id="LAY-list-normal2"  lay-filter="LAY-list-normal2"></table>
                    <!-- 行内工具 -->
                    <script type="text/html" id="operation2">
                        {{# if(d.manufacture_status==2 || d.manufacture_status==4){ }}
                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="submit" href="javascript:;">提交</a>
                        {{# } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<style>
    #weight:after {
        content: 'g';
        position: absolute;
        top: 0px;
        right: 10px;
    }
    .category_id .xm-select-title{
        width: 500px;
    }
    .layui-table-cell {
        height: auto;
        overflow: visible;
        text-overflow: inherit;
        white-space: normal;
        line-height: normal;
    }
</style>
<script>
    layui.use(['admin', 'table', 'form', 'common', 'formSelects', 'laydate', 'laytpl','upload', 'element','toolJ'], function () {
        var $ = layui.$
            , admin = layui.admin
            , view = layui.view
            , table = layui.table
            , laytpl = layui.laytpl
            , upload = layui.upload
            , laydate = layui.laydate
            , formSelects = layui.formSelects
           // , toolJ = layui.common
            , toolJJ = layui.toolJ
            , element = layui.element
            , form = layui.form;

        for (i = 1; i <= 4; i++) { 
            laydate.render({ elem: ('#date'+i) , type: 'date' , range: true });
        }
//        $("select[name='status']").val(2);

        form.render(null);
        formSelects.render();
        formSelects.value('select1',[2,4], true);
        formSelects.value('select2',[2,4], true);
        //批量操作
        form.on('select(batchOp2)', function(data){
            switch (data.value) {
                case '1':
                    var url = '/index/Datamanufacture/exportDataManufactureListedit';
                    var data = form.val("LAY-list-form");
                    data.type = 'edit';
                    toolJJ.ajax({"data": data, 'url': url});
                    break;
                case '2':
                    var url = '/index/Datamanufacture/uploadManufactureEdit';
                    var template = '/attachment/importcvs/editmanufacture.csv'; 
                    toolJJ.upload(url, template);
                    break;
            }
            form.render(null, 'batchOp-form2');
            layui.$("div[lay-filter='batchOp-form2'] dd[lay-value=0]").remove();
        });
        layui.$("div[lay-filter='batchOp-form2'] dd[lay-value=0]").remove();

        var u={};
        u[layui.data(layui.setter.tableName).access_token]=layui.data(layui.setter.tableName).cn_name;
        toolJJ.formSelectsArr(u, 'user',[layui.data(layui.setter.tableName).access_token]);
        toolJJ.formSelectsArr(u, 'user1',[layui.data(layui.setter.tableName).access_token]);

        $('.tabreset').click(function(){
            var url = window.location.toString();
            location = url.split('#')[0]+'#'+url.split('#')[1]+'#'+$("#tabtype").val()+Math.ceil(Math.random()*10);
            layui.$("div[lay-filter='batchOp-form'] dd[lay-value=0]").remove();
        });

        var url = window.location.toString();
        var tablayid = url.split('#')[2];
        if(tablayid){
            tablayid = tablayid.slice(0, 1);
            element.tabChange('showInfo', tablayid);
            $("#tabtype").val(tablayid);
            $('.search'+tablayid).click();
        }

        
        element.on('tab(showInfo)', function () {
            var layid = $(this).attr('lay-id');
            $("#tabtype").val(layid);
            $('.search'+layid).click();
            layui.$("div[lay-filter='batchOp-form'] dd[lay-value=0]").remove();
            var u={};
            u[layui.data(layui.setter.tableName).access_token]=layui.data(layui.setter.tableName).cn_name;
            toolJJ.formSelectsArr(u, 'user',[layui.data(layui.setter.tableName).access_token]);
            toolJJ.formSelectsArr(u, 'user1',[layui.data(layui.setter.tableName).access_token]);
        });
        viewTable();
        layui.form.on('submit(LAY-list-search)', function (data) {
            var field = data.field;
            viewTable(field);
        });
        //批量操作
        form.on('select(batchOp)', function(data){
            switch (data.value) {
                case '1':
                    var url = '/index/Datamanufacture/exportDataManufactureListimg';
                    var data = form.val("LAY-list-form1");
                    data.type = 'img';
                    toolJJ.ajax({"data": data, 'url': url});
                    break;
                case '2':
                    var url = '/index/Datamanufacture/uploadImgSubmitInfo';
                    var template = '/attachment/importcvs/imgsubmit.csv'; 
                    toolJJ.upload(url, template);
                    break;
            }
            form.render(null, 'batchOp-form');
            layui.$("div[lay-filter='batchOp-form'] dd[lay-value=0]").remove();
        });
        layui.$("div[lay-filter='batchOp-form'] dd[lay-value=0]").remove();
        
        function  viewTable(field = '') {

            if(field == ''){
                field = {};
                field.operator = layui.data(layui.setter.tableName).access_token;
                field.status = "2,4";
            } 
            field.type = ($("#tabtype").val() == 1)?'edit':'img';
            if(field.type=='edit'){
//                field.status=$("select[name='status']").eq(0).val();
                var res = formSelects.value('select1','val');
                formSelects.value('select1',res, true);
            }else{
//                field.status=$("select[name='status']").eq(1).val();
                var res = formSelects.value('select2','val');
                formSelects.value('select2',res, true);
            }

            var param = [
                {field: 'skuinfo', title: 'SKU信息'}
                , {field: field.type+'materialinfo', title: '资料信息'}
                , {field: field.type+'manufactureinfo', title: '制作信息'}
                , {field: field.type+'personalinfo', title: '人员信息'}
                , {field: 'timeinfo', title: '时间信息'}
                , {field: 'mstatus_name', title: '制作状态'}
                , {field: 'handover_remarks', title: '交接备注'}
                , {field: 'audit_remarks', title: '审核备注'}
                , {fixed: 'right', title:'操作', toolbar: '#operation'+$("#tabtype").val(), width:60}
            ];

           var ele = 'LAY-list-normal' + $("#tabtype").val();
            table.render({
                elem: "#" + ele
                , url: '/index/Datamanufacture/getDataManufactureList'+field.type
                , where: field
                , cols: [param]
                , page: true
                , limit: 50
                ,text:{none: '暂无相关数据!' }
            });

            //监听行内操作
            table.on('tool(LAY-list-normal2)', function(obj){
                // debugger;
                switch (obj.event) {
                    case 'submit':
                        layer.open({
                            type: 1
                            ,title: '提交'
                            ,area: ['230px', '150px']
                            ,shade: 0.8
                            ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
                            ,btn: ['确定','取消']
                            ,btn1: function(index, layero){
                                var a = {};
                                a.url = '/index/Datamanufacture/updateManufactureStatus';
                                a.data ={sku:obj.data.sku};
                                toolJJ.ajax(a);
                                $('.search'+$("#tabtype").val()).click();
                                return false;
                            }
                            ,content: '<div class="layui-card" style="padding: 10px 30px 10px 60px" >是否确认提交？</div>'
                            ,success: function(layero){
                                form.render(null, 'LAY-list-form1');
                            }
                          });
                        break;
                }
            });
        }
    });
</script>